package com.example.demo.nio;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.Callable;

@RestController
@RequestMapping("/app")
public class NIOCtrl {

    @Autowired
    private LocalNewsAsyncContext localNewsAsyncContext;

    @Autowired
    private NewsService newsService;

    @RequestMapping("/news")
    public void getNews(HttpServletRequest request,@RequestParam(value = "type",required = false) String type){
        if("1".equals(type)){
            localNewsAsyncContext.submit(request, () -> newsService.getNews());
            return;
        }
        localNewsAsyncContext.submit(request, () -> newsService.getNewsMap());
    }
}
